'''
Created on Jan 19, 2010

@author: madsk
'''

from PyQt4 import QtGui, QtCore

class Mediator(QtCore.QObject):
    clicked = QtCore.pyqtSignal()
    
    def __init__(self):
        super(Mediator, self).__init__()
        

class OverlayButton(QtGui.QGraphicsItem):
    BASE_RECT = QtCore.QRectF(0, 0, 100, 100)
    
    def __init__(self, parent=None, scene=None):
        QtGui.QGraphicsItem.__init__(self, parent, scene)
        self._mediator = Mediator()
        
        # Create the button outline.
        self.setOpacity(0.7)
        self.setFlag(QtGui.QGraphicsItem.ItemIsFocusable)
        
        # Create the base image.
        self._path = QtGui.QPainterPath()
        self._path.addRect(OverlayButton.BASE_RECT)
            
    def shape(self):
        return self._path
    
    def boundingRect(self):
        return self._path.boundingRect()
    
    def paint(self, painter, option, widget=None):
#        painter.setPen(QtCore.Qt.SolidLine)
        painter.setBrush(QtGui.QBrush(QtGui.QColor(0,0,0)))
        painter.drawRoundedRect(OverlayButton.BASE_RECT, 5, 5)

    def clicked(): #@NoSelf
        def fget(self):
            return self._mediator.clicked
        return locals()
    clicked = property(**clicked())